**************************************************************************************************
*** This do file creates the replication results for 
*** Geographies of educational mobilities: exploring the uneven flows of international students	*/
*** Richard Perkins (LSE)																		*/
*** Eric Neumayer (LSE)																			*/
*** 																							*/
*** Published in: The Geographical Journal, 180 (3), 2014, pp. 246-259															*/
**************************************************************************************************
**************************************************************************************************
/* Note: 
You have to change "local DIR" to the directory you copy the original stata files contained 	*/
/* in the zip file and then run the do file. 													*/
**************************************************************************************************

version 12.0
drop _all
clear matrix
clear mata
set mem 800m
set mat 5000

capture net install outreg2, from(http://fmwww.bc.edu/RePEc/bocode/o)			/* checks whether outreg2 is installed 		*/

***********************************************************************************
local DIR = "C:\Research\Asylum and Migration\Student migration data\"  /*change relative path to the directory where the files are located */
cd "`DIR'"
***********************************************************************************

use  "Article for Geographical Journal (student migration).dta", replace

*** Descriptive analysis in section "Mapping the uneven patterns of ISM"
preserve

keep if year==2009
egen studentnumbers_rounded_global=sum(studentnumbers_rounded)
gen studentnumbers_rounded_share=studentnumbers_rounded/ studentnumbers_rounded_global

egen developing_to_developed=sum(studentnumbers_rounded_share) if  inc_high_oecd_dest==1 &  inc_high_oecd_orig==0
su developing_to_developed
egen developing_to_developing=sum(studentnumbers_rounded_share) if  inc_high_oecd_dest==0 &  inc_high_oecd_orig==0
su developing_to_developing
egen developed_to_developed=sum(studentnumbers_rounded_share) if  inc_high_oecd_dest==1 &  inc_high_oecd_orig==1
su developed_to_developed
egen developed_to_developing=sum(studentnumbers_rounded_share) if  inc_high_oecd_dest==0 &  inc_high_oecd_orig==1
su developed_to_developing

egen emmark_to_developed=sum(studentnumbers_rounded_share) if  inc_high_oecd_dest==1 &  brics_nics_orig==1 & origin!="Russian Federation" & origin!="Korea, Rep."
su emmark_to_developed
egen emmark_to_all=sum(studentnumbers_rounded_share) if  brics_nics_orig==1  & origin!="Russian Federation" & origin!="Korea, Rep."
su emmark_to_all

egen low_to_developed=sum(studentnumbers_rounded_share) if  inc_high_oecd_dest==1 & inc_low_orig==1
su low_to_developed
egen low_to_all=sum(studentnumbers_rounded_share) if  inc_low_orig==1
su low_to_all


restore

preserve

keep if (year==1999 | year==2009)
egen studentnumbers_rounded_global=sum(studentnumbers_rounded), by(year)
gen studentnumbers_rounded_share=studentnumbers_rounded/ studentnumbers_rounded_global

egen from_developing=sum(studentnumbers_rounded_share) if  inc_high_oecd_orig==0 & inc_high_orig==0, by(year)
su from_developing if year==1999
su from_developing if year==2009

restore


tsset dyadid year

*** Table 1: summary descriptive variable analysis
quietly xi: nbreg  studentnumbers_rounded    thes_rankings_destination thes_rankings_origin  lnmigrantstock_orig_in_dest    lndistance   coloniallink comlang  english_firstlang_dest         lngdppcconst_destination lngdppcconst_origin   gdppcconst_dest_origin_ratio polity2_destination polity2_origin    lnpop_at_tert_edu_dest lnpop_at_tert_edu_origin      i.year if   year<2010, cluster(dyadid) nolrtest
su  studentnumbers_rounded    thes_rankings_destination thes_rankings_origin arwu_rankings500_destination arwu_rankings500_origin  lnmigrantstock_orig_in_dest    lndistance   coloniallink comlang  english_firstlang_dest         lngdppcconst_destination lngdppcconst_origin   gdppcconst_dest_origin_ratio polity2_destination polity2_origin   lnpop_at_tert_edu_dest lnpop_at_tert_edu_origin if e(sample)


*** Table 2: Main estimation results
** THES uni ranking variable
* model 1
xi: nbreg  studentnumbers_rounded    thes_rankings_destination thes_rankings_origin  lnmigrantstock_orig_in_dest    lndistance   coloniallink comlang  english_firstlang_dest         lngdppcconst_destination lngdppcconst_origin   gdppcconst_dest_origin_ratio  polity2_destination polity2_origin     lnpop_at_tert_edu_dest lnpop_at_tert_edu_origin       i.year if   year<2010, cluster(dyadid) nolrtest
su year if e(sample)
outreg2 using table2, replace excel 2aster
corr thes_rankings_destination arwu_rankings500_destination if e(sample)
*listcoef, percent help 

** ARWU ranking variable
* model 2
xi: nbreg  studentnumbers_rounded    arwu_rankings500_destination arwu_rankings500_origin lnmigrantstock_orig_in_dest    lndistance   coloniallink comlang  english_firstlang_dest         lngdppcconst_destination lngdppcconst_origin   gdppcconst_dest_origin_ratio polity2_destination polity2_origin    lnpop_at_tert_edu_dest lnpop_at_tert_edu_origin     i.year if   year<2010, cluster(dyadid) nolrtest
su year if e(sample)
outreg2 using table2, append excel 2aster
*listcoef, percent help 



*** Table 3: Spatial variation in the effect of central variables by income grouping of origin

** THES uni ranking variable
* model 1
xi: nbreg  studentnumbers_rounded    thes_rankings_destination thes_rankings_origin  lnmigrantstock_orig_in_dest    lndistance   coloniallink comlang  english_firstlang_dest         lngdppcconst_destination lngdppcconst_origin   gdppcconst_dest_origin_ratio  polity2_destination    polity2_origin  lnpop_at_tert_edu_dest lnpop_at_tert_edu_origin    i.year if   year<2010  & (inc_high_oecd_orig==1 | inc_high_orig==1),  nolrtest 
estimates store rich

xi: nbreg  studentnumbers_rounded    thes_rankings_destination thes_rankings_origin  lnmigrantstock_orig_in_dest    lndistance   coloniallink comlang  english_firstlang_dest         lngdppcconst_destination lngdppcconst_origin   gdppcconst_dest_origin_ratio  polity2_destination    polity2_origin  lnpop_at_tert_edu_dest lnpop_at_tert_edu_origin    i.year if   year<2010  & inc_high_oecd_orig==0 & inc_high_orig==0,  nolrtest
estimates store poor

xi: nbreg  studentnumbers_rounded    thes_rankings_destination thes_rankings_origin  lnmigrantstock_orig_in_dest    lndistance   coloniallink comlang  english_firstlang_dest         lngdppcconst_destination lngdppcconst_origin   gdppcconst_dest_origin_ratio   polity2_destination    polity2_origin lnpop_at_tert_edu_dest lnpop_at_tert_edu_origin    i.year if   year<2010 & inc_low_orig==1,  nolrtest
estimates store low

xi: nbreg  studentnumbers_rounded    thes_rankings_destination thes_rankings_origin  lnmigrantstock_orig_in_dest    lndistance   coloniallink comlang  english_firstlang_dest         lngdppcconst_destination lngdppcconst_origin   gdppcconst_dest_origin_ratio   polity2_destination    polity2_origin lnpop_at_tert_edu_dest lnpop_at_tert_edu_origin    i.year if   year<2010 & emmark_orig==1,  nolrtest
estimates store brics

suest rich poor brics low, cluster(dyad)
outreg2 using table9, replace excel 2aster

* Test rich versus poor
test [rich_studentnumbers_rounded]thes_rankings_destination=[poor_studentnumbers_rounded]thes_rankings_destination
test [rich_studentnumbers_rounded]thes_rankings_origin=[poor_studentnumbers_rounded]thes_rankings_origin
test [rich_studentnumbers_rounded]lnmigrantstock_orig_in_dest=[poor_studentnumbers_rounded]lnmigrantstock_orig_in_dest
test [rich_studentnumbers_rounded]lndistance=[poor_studentnumbers_rounded]lndistance
test [rich_studentnumbers_rounded]coloniallink=[poor_studentnumbers_rounded]coloniallink
test [rich_studentnumbers_rounded]comlang=[poor_studentnumbers_rounded]comlang
test [rich_studentnumbers_rounded]english_firstlang_dest=[poor_studentnumbers_rounded]english_firstlang_dest
test [rich_studentnumbers_rounded]lngdppcconst_destination=[poor_studentnumbers_rounded]lngdppcconst_destination
test [rich_studentnumbers_rounded]lngdppcconst_origin=[poor_studentnumbers_rounded]lngdppcconst_origin
test [rich_studentnumbers_rounded]gdppcconst_dest_origin_ratio=[poor_studentnumbers_rounded]gdppcconst_dest_origin_ratio
test [rich_studentnumbers_rounded]lnpop_at_tert_edu_dest=[poor_studentnumbers_rounded]lnpop_at_tert_edu_dest
test [rich_studentnumbers_rounded]lnpop_at_tert_edu_origin=[poor_studentnumbers_rounded]lnpop_at_tert_edu_origin
test [rich_studentnumbers_rounded]polity2_origin=[poor_studentnumbers_rounded]polity2_origin
test [rich_studentnumbers_rounded]polity2_destination=[poor_studentnumbers_rounded]polity2_destination

* Test poor versus low-income
test [poor_studentnumbers_rounded]thes_rankings_destination=[low_studentnumbers_rounded]thes_rankings_destination
test [poor_studentnumbers_rounded]thes_rankings_origin=[low_studentnumbers_rounded]thes_rankings_origin
test [poor_studentnumbers_rounded]lnmigrantstock_orig_in_dest=[low_studentnumbers_rounded]lnmigrantstock_orig_in_dest
test [poor_studentnumbers_rounded]lndistance=[low_studentnumbers_rounded]lndistance
test [poor_studentnumbers_rounded]coloniallink=[low_studentnumbers_rounded]coloniallink
test [poor_studentnumbers_rounded]comlang=[low_studentnumbers_rounded]comlang
test [poor_studentnumbers_rounded]english_firstlang_dest=[low_studentnumbers_rounded]english_firstlang_dest
test [poor_studentnumbers_rounded]lngdppcconst_destination=[low_studentnumbers_rounded]lngdppcconst_destination
test [poor_studentnumbers_rounded]lngdppcconst_origin=[low_studentnumbers_rounded]lngdppcconst_origin
test [poor_studentnumbers_rounded]gdppcconst_dest_origin_ratio=[low_studentnumbers_rounded]gdppcconst_dest_origin_ratio
test [poor_studentnumbers_rounded]lnpop_at_tert_edu_dest=[low_studentnumbers_rounded]lnpop_at_tert_edu_dest
test [poor_studentnumbers_rounded]lnpop_at_tert_edu_origin=[low_studentnumbers_rounded]lnpop_at_tert_edu_origin
test [poor_studentnumbers_rounded]polity2_origin=[low_studentnumbers_rounded]polity2_origin
test [poor_studentnumbers_rounded]polity2_destination=[low_studentnumbers_rounded]polity2_destination


* Test poor versus BRICS
test [poor_studentnumbers_rounded]thes_rankings_destination=[brics_studentnumbers_rounded]thes_rankings_destination
test [poor_studentnumbers_rounded]thes_rankings_origin=[brics_studentnumbers_rounded]thes_rankings_origin
test [poor_studentnumbers_rounded]lnmigrantstock_orig_in_dest=[brics_studentnumbers_rounded]lnmigrantstock_orig_in_dest
test [poor_studentnumbers_rounded]lndistance=[brics_studentnumbers_rounded]lndistance
test [poor_studentnumbers_rounded]coloniallink=[brics_studentnumbers_rounded]coloniallink
test [poor_studentnumbers_rounded]comlang=[brics_studentnumbers_rounded]comlang
test [poor_studentnumbers_rounded]english_firstlang_dest=[brics_studentnumbers_rounded]english_firstlang_dest
test [poor_studentnumbers_rounded]lngdppcconst_destination=[brics_studentnumbers_rounded]lngdppcconst_destination
test [poor_studentnumbers_rounded]lngdppcconst_origin=[brics_studentnumbers_rounded]lngdppcconst_origin
test [poor_studentnumbers_rounded]gdppcconst_dest_origin_ratio=[brics_studentnumbers_rounded]gdppcconst_dest_origin_ratio
test [poor_studentnumbers_rounded]lnpop_at_tert_edu_dest=[brics_studentnumbers_rounded]lnpop_at_tert_edu_dest
test [poor_studentnumbers_rounded]lnpop_at_tert_edu_origin=[brics_studentnumbers_rounded]lnpop_at_tert_edu_origin
test [poor_studentnumbers_rounded]polity2_origin=[brics_studentnumbers_rounded]polity2_origin
test [poor_studentnumbers_rounded]polity2_destination=[brics_studentnumbers_rounded]polity2_destination

* Test rich versus BRICS
test [rich_studentnumbers_rounded]thes_rankings_destination=[brics_studentnumbers_rounded]thes_rankings_destination
test [rich_studentnumbers_rounded]thes_rankings_origin=[brics_studentnumbers_rounded]thes_rankings_origin
test [rich_studentnumbers_rounded]lnmigrantstock_orig_in_dest=[brics_studentnumbers_rounded]lnmigrantstock_orig_in_dest
test [rich_studentnumbers_rounded]coloniallink=[brics_studentnumbers_rounded]coloniallink
test [rich_studentnumbers_rounded]comlang=[brics_studentnumbers_rounded]comlang
test [rich_studentnumbers_rounded]english_firstlang_dest=[brics_studentnumbers_rounded]english_firstlang_dest
test [rich_studentnumbers_rounded]lngdppcconst_destination=[brics_studentnumbers_rounded]lngdppcconst_destination
test [rich_studentnumbers_rounded]lngdppcconst_origin=[brics_studentnumbers_rounded]lngdppcconst_origin
test [rich_studentnumbers_rounded]gdppcconst_dest_origin_ratio=[brics_studentnumbers_rounded]gdppcconst_dest_origin_ratio
test [rich_studentnumbers_rounded]lnpop_at_tert_edu_dest=[brics_studentnumbers_rounded]lnpop_at_tert_edu_dest
test [rich_studentnumbers_rounded]lnpop_at_tert_edu_origin=[brics_studentnumbers_rounded]lnpop_at_tert_edu_origin
test [rich_studentnumbers_rounded]polity2_origin=[brics_studentnumbers_rounded]polity2_origin
test [rich_studentnumbers_rounded]polity2_destination=[brics_studentnumbers_rounded]polity2_destination

* Test BRICS versus low-income
test [brics_studentnumbers_rounded]thes_rankings_destination=[low_studentnumbers_rounded]thes_rankings_destination
test [brics_studentnumbers_rounded]thes_rankings_origin=[low_studentnumbers_rounded]thes_rankings_origin
test [brics_studentnumbers_rounded]lnmigrantstock_orig_in_dest=[low_studentnumbers_rounded]lnmigrantstock_orig_in_dest
test [brics_studentnumbers_rounded]lndistance=[low_studentnumbers_rounded]lndistance
test [brics_studentnumbers_rounded]coloniallink=[low_studentnumbers_rounded]coloniallink
test [brics_studentnumbers_rounded]comlang=[low_studentnumbers_rounded]comlang
test [brics_studentnumbers_rounded]english_firstlang_dest=[low_studentnumbers_rounded]english_firstlang_dest
test [brics_studentnumbers_rounded]lngdppcconst_destination=[low_studentnumbers_rounded]lngdppcconst_destination
test [brics_studentnumbers_rounded]lngdppcconst_origin=[low_studentnumbers_rounded]lngdppcconst_origin
test [brics_studentnumbers_rounded]gdppcconst_dest_origin_ratio=[low_studentnumbers_rounded]gdppcconst_dest_origin_ratio
test [brics_studentnumbers_rounded]lnpop_at_tert_edu_dest=[low_studentnumbers_rounded]lnpop_at_tert_edu_dest
test [brics_studentnumbers_rounded]lnpop_at_tert_edu_origin=[low_studentnumbers_rounded]lnpop_at_tert_edu_origin
test [brics_studentnumbers_rounded]polity2_origin=[low_studentnumbers_rounded]polity2_origin
test [brics_studentnumbers_rounded]polity2_destination=[low_studentnumbers_rounded]polity2_destination




*** temporal variations
preserve 

egen dyad_entire_period_count=count(studentnumbers_rounded), by(origin destination)

keep if dyad_entire_period_count==11

xi: nbreg  studentnumbers_rounded  lnmigrantstock_orig_in_dest c.year##c.lnmigrantstock_orig_in_dest    lndistance   coloniallink comlang  english_firstlang_dest      polity2_origin polity2_destination     lngdppcconst_destination lngdppcconst_origin   gdppcconst_dest_origin_ratio  polity2_destination    polity2_origin   lnpop_at_tert_edu_dest lnpop_at_tert_edu_origin      if  year<2010, cluster(dyadid) nolrtest
margins, eydx(lnmigrantstock_orig_in_dest ) at(year=(1999(1)2009))  atmeans level(90) post
outreg2 using table4, replace excel
marginsplot, title("figure_migrantstock")
graph export  figure_migrantstock.eps, replace


xi: nbreg  studentnumbers_rounded  lndistance c.year##c.lndistance  lnmigrantstock_orig_in_dest       coloniallink comlang  english_firstlang_dest      polity2_origin polity2_destination     lngdppcconst_destination lngdppcconst_origin   gdppcconst_dest_origin_ratio   polity2_destination    polity2_origin  lnpop_at_tert_edu_dest lnpop_at_tert_edu_origin      if  year<2010, cluster(dyadid) nolrtest
margins, eydx(lndistance ) at(year=(1999(1)2009))  atmeans level(90) post
outreg2 using table4, append excel
marginsplot, title("figure_lndistance")
graph export  figure_lndistance.eps, replace


xi: nbreg  studentnumbers_rounded  comlang c.year##c.comlang  lnmigrantstock_orig_in_dest    lndistance   coloniallink   english_firstlang_dest      polity2_origin polity2_destination     lngdppcconst_destination lngdppcconst_origin   gdppcconst_dest_origin_ratio  polity2_destination    polity2_origin   lnpop_at_tert_edu_dest lnpop_at_tert_edu_origin      if  year<2010, cluster(dyadid) nolrtest
margins, eydx(comlang ) at(year=(1999(1)2009))  atmeans level(90) post
outreg2 using table4, append excel
marginsplot, title("figure_comlang")
graph export  figure_comlang.eps, replace

xi: nbreg  studentnumbers_rounded  english_firstlang_dest c.year##c.english_firstlang_dest  lnmigrantstock_orig_in_dest    lndistance   coloniallink comlang  english_firstlang_dest       polity2_origin polity2_destination     lngdppcconst_destination lngdppcconst_origin   gdppcconst_dest_origin_ratio  polity2_destination    polity2_origin   lnpop_at_tert_edu_dest lnpop_at_tert_edu_origin      if  year<2010, cluster(dyadid) nolrtest
margins, eydx(english_firstlang_dest ) at(year=(1999(1)2009))  atmeans level(90) post
outreg2 using table4, append excel
marginsplot, title("figure_englis_nonoecd")
graph export  figure_englis_nonoecd.eps, replace


xi: nbreg  studentnumbers_rounded  lngdppcconst_destination c.year##c.lngdppcconst_destination   lnmigrantstock_orig_in_dest    lndistance   coloniallink comlang   english_firstlang_dest      polity2_origin polity2_destination      lngdppcconst_origin   gdppcconst_dest_origin_ratio   polity2_destination    polity2_origin  lnpop_at_tert_edu_dest lnpop_at_tert_edu_origin      if  year<2010, cluster(dyadid) nolrtest
margins, eydx(lngdppcconst_destination ) at(year=(1999(1)2009))  atmeans level(90) post
outreg2 using table4, append excel
marginsplot, title("figure_lngdppc_dest")
graph export  figure_lngdppc_dest.eps, replace

xi: nbreg  studentnumbers_rounded  lngdppcconst_origin c.year##c.lngdppcconst_origin   lnmigrantstock_orig_in_dest    lndistance   coloniallink comlang   english_firstlang_dest      polity2_origin polity2_destination     lngdppcconst_destination    gdppcconst_dest_origin_ratio  polity2_destination    polity2_origin   lnpop_at_tert_edu_dest lnpop_at_tert_edu_origin      if  year<2010, cluster(dyadid) nolrtest
margins, eydx(lngdppcconst_origin ) at(year=(1999(1)2009))  atmeans level(90) post
outreg2 using table4, append excel
marginsplot, title("figure_lngdppc_origin")
graph export  figure_lngdppc_origin.eps, replace

xi: nbreg  studentnumbers_rounded gdppcconst_dest_origin_ratio  c.year##c.gdppcconst_dest_origin_ratio   lnmigrantstock_orig_in_dest    lndistance   coloniallink comlang   english_firstlang_dest      polity2_origin polity2_destination     lngdppcconst_destination lngdppcconst_origin    polity2_destination    polity2_origin    lnpop_at_tert_edu_dest lnpop_at_tert_edu_origin      if  year<2010, cluster(dyadid) nolrtest
margins, eydx(gdppcconst_dest_origin_ratio ) at(year=(1999(1)2009))  atmeans level(90) post
outreg2 using table4, append excel
marginsplot, title("figure_gdppc_dest_origin_ratio")
graph export  figure_gdppc_dest_origin_ratio.eps, replace

xi: nbreg  studentnumbers_rounded  polity2_origin c.year##c.polity2_origin  lnmigrantstock_orig_in_dest    lndistance   coloniallink   english_firstlang_dest       polity2_destination     lngdppcconst_destination lngdppcconst_origin   gdppcconst_dest_origin_ratio   lnpop_at_tert_edu_dest lnpop_at_tert_edu_origin      if  year<2010, cluster(dyadid) nolrtest
margins, eydx(polity2_origin ) at(year=(1999(1)2009))  atmeans level(90) post
outreg2 using table4, append excel
marginsplot, title("figure_comlang")
graph export  figure_polity2_origin.eps, replace

xi: nbreg  studentnumbers_rounded  polity2_destination c.year##c.polity2_destination  lnmigrantstock_orig_in_dest    lndistance   coloniallink   english_firstlang_dest      polity2_origin polity2_destination     lngdppcconst_destination lngdppcconst_origin   gdppcconst_dest_origin_ratio   polity2_destination    polity2_origin  lnpop_at_tert_edu_dest lnpop_at_tert_edu_origin      if  year<2010, cluster(dyadid) nolrtest
margins, eydx(polity2_destination ) at(year=(1999(1)2009))  atmeans level(90) post
outreg2 using table4, append excel
marginsplot, title("figure_comlang")
graph export  figure_polity2_destination.eps, replace

restore
